# Copyright (C) 2015 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Perftest description file for building the "gmonster1" benchmark.
# Where does the name come from?  The benchmark is derived from one of the
# monster programs at Google.
#
# Perftest descriptions are loaded thrice:
# 1) To generate the build .exp files
#    GDB_PERFTEST_MODE=gen-build-exps
#    This step allows for parallel builds of the majority of pieces of the
#    test binary and shlibs.
# 2) To compile the "pieces" of the binary and shlibs.
#    "Pieces" are the bulk of the machine-generated sources of the test.
#    This step is driven by lib/build-piece.exp.
#    GDB_PERFTEST_MODE=build-pieces
# 3) To perform the final link of the binary and shlibs.
#    GDB_PERFTEST_MODE=compile
#
# Example usage:
# bash$ make -j5 build-perf RUNTESTFLAGS="gmonster1.exp gmonster2.exp"
# bash$ make check-perf RUNTESTFLAGS="gdb.perf/gm*-*.exp GDB=/path/to/gdb"

load_lib perftest.exp
load_lib gen-perf-test.exp

if [skip_perf_tests] {
    return 0
}

if ![info exists MONSTER] {
    set MONSTER "n"
}

proc make_testcase_config { } {
    global MONSTER

    set program_name "gmonster1"
    array set testcase [GenPerfTest::init_testcase $program_name]

    set testcase(language) c++

    # *_{sources,headers} need to be embedded in an outer list
    # because remember each element of the outer list is for each run, and
    # here we want to use the same value for all runs.
    set testcase(binary_extra_sources) { { gmonster1.cc gm-hello.cc gm-use-cerr.cc gm-pervasive-typedef.cc } }
    set testcase(binary_extra_headers) { { <stdint.h> gm-utils.h gm-std.h gm-pervasive-typedef.h } }
    set testcase(tail_shlib_sources) { { gm-std.cc } }
    set testcase(tail_shlib_headers) { { gm-std.h } }

    if { $MONSTER == "y" } {
	set testcase(run_names) { 10-cus 100-cus 1000-cus 10000-cus }
	set testcase(nr_compunits) { 10 100 1000 10000 }
    } else {
	set testcase(run_names) { 1-cu 10-cus 100-cus }
	set testcase(nr_compunits) { 1 10 100 }
    }
    set testcase(nr_gen_shlibs) { 0 }

    set testcase(nr_extern_globals) 10
    set testcase(nr_static_globals) 10
    set testcase(nr_extern_functions) 10
    set testcase(nr_static_functions) 10

    # class_specs needs to be embedded in an outer list because remember
    # each element of the outer list is for each run, and here we want to use
    # the same value for all runs.
    set testcase(class_specs) { {
	{
	    count 1 name { class }
	    nr_members 10 nr_static_members 10
	    nr_methods 10 nr_static_methods 10
	    nr_inline_methods 10 nr_static_inline_methods 10
	}
	{
	    count 1 name { ns0 class }
	    nr_members 10 nr_static_members 10
	    nr_methods 10 nr_static_methods 10
	    nr_inline_methods 10 nr_static_inline_methods 10
	}
	{
	    count 1 name { ns0 anonymous aclass }
	    nr_members 10 nr_static_members 10
	    nr_methods 10 nr_static_methods 10
	    nr_inline_methods 10 nr_static_inline_methods 10
	}
	{
	    count 1 name { ns0 ns1 class }
	    nr_members 10 nr_static_members 10
	    nr_methods 10 nr_static_methods 10
	    nr_inline_methods 10 nr_static_inline_methods 10
	}
	{
	    count 1 name { ns0 anonymous ns1 aclass }
	    nr_members 10 nr_static_members 10
	    nr_methods 10 nr_static_methods 10
	    nr_inline_methods 10 nr_static_inline_methods 10
	}
    } }

    return [array get testcase]
}

GenPerfTest::standard_compile_driver gmonster1.exp make_testcase_config
